function theta=estimate(config_id,config,input)

    %%%%%%%%%%%%%%%%%%
    % UNCONSTRAINED QUANTILE REGRESSION
    %%%%%%%%%%%%%%%%%%

if config_id==1, 

        %%%%%%%%%%%%%%%%%%
        % LOAD IN
        %%%%%%%%%%%%%%%%%%

    S=config.S;
    share=config.share;
    tau=config.tau;
       
        %%%%%%%%%%%%%%%%%%
        % ESTIMATE
        %%%%%%%%%%%%%%%%%%
        
    theta=qreg_NAG(S,share,tau,NaN,0);
                  
end;

    %%%%%%%%%%%%%%%%%%
    % CONSTRAINED QUANTILE REGRESSION
    %%%%%%%%%%%%%%%%%%

if config_id==2, 

        %%%%%%%%%%%%%%%%%%
        % LOAD IN
        %%%%%%%%%%%%%%%%%%

    S=config.S;
    p=config.p;
    y=config.y;

    p_grid_constraint=config.p_grid_constraint;
    y_grid_constraint=config.y_grid_constraint;
        
    share=config.share;
    tau=config.tau;
    
    xi1=config.xi1;
    xi2=config.xi2;
    
    n1=input.n1;
    k1=input.k1;
    n2=input.n2;
    k2=input.k2;
       
        %%%%%%%%%%%%%%%%%%
        % ESTIMATE
        %%%%%%%%%%%%%%%%%%

    set_constraint=1;   

    theta0=qreg_NAG(S,share,tau,NaN,0);
    x0_start_mat=[theta0 0*theta0 1.05*theta0 0.95*theta0 ones(size(theta0,1),1) randn(size(theta0,1),10)];
    gamma=1e-6;
    user_input=user_pack(share,p,y,xi1,xi2,n1,n2,k1,k2,tau,gamma,p_grid_constraint,y_grid_constraint);
        
    theta=reg_demand_share(user_input,x0_start_mat,set_constraint);
                
end;

    %%%%%%%%%%%%%%%%%%
    % UNCONSTRAINED B-SPLINE MEAN
    %%%%%%%%%%%%%%%%%%

if config_id==3, 

        %%%%%%%%%%%%%%%%%%
        % LOAD IN
        %%%%%%%%%%%%%%%%%%

    S=config.S;
    p=config.p;
    y=config.y;
        
    share=config.share;
    tau=config.tau;

    p_grid_constraint=NaN*config.p_grid_constraint;
    y_grid_constraint=NaN*config.y_grid_constraint;
    
    xi1=config.xi1;
    xi2=config.xi2;
    
    n1=input.n1;
    k1=input.k1;
    n2=input.n2;
    k2=input.k2;
    
    
        %%%%%%%%%%%%%%%%%%
        % ESTIMATE
        %%%%%%%%%%%%%%%%%%

    set_constraint=0;
    
    theta_input=qreg_NAG(S,share,tau,NaN,0);

    start_OLS=theta_input;
    
    gamma=1e-6;
        
    user_input=user_pack(share,p,y,xi1,xi2,n1,n2,k1,k2,tau,gamma,p_grid_constraint,y_grid_constraint);
        
    theta=reg_demand_share_mean(user_input,start_OLS,set_constraint);
            
        %%%%%%%%%%%%%%%%%%
        % OUTPUT
        %%%%%%%%%%%%%%%%%%
    
end;

    %%%%%%%%%%%%%%%%%%
    % UNCONSTRAINED B-SPLINE MEAN
    %%%%%%%%%%%%%%%%%%

if config_id==4, 

        %%%%%%%%%%%%%%%%%%
        % LOAD IN
        %%%%%%%%%%%%%%%%%%

    S=config.S;
    p=config.p;
    y=config.y;
    share=config.share;
    tau=config.tau;
    
    p_grid_constraint=config.p_grid_constraint;
    y_grid_constraint=config.y_grid_constraint;

    xi1=config.xi1;
    xi2=config.xi2;
    n1=input.n1;
    k1=input.k1;
    n2=input.n2;
    k2=input.k2;
        
        %%%%%%%%%%%%%%%%%%
        % ESTIMATE
        %%%%%%%%%%%%%%%%%%

    set_constraint=1;
    
    theta0=qreg_NAG(S,share,tau,NaN,0);

    N=size(p,1);
    matX=[ones(N,1) p y];
    ols=(matX'*matX)^(-1)*matX'*share;
    share_ols=matX*ols;
    
    theta0_straight=qreg_NAG(S,share_ols,tau,NaN,0);

    x0_start_mat=[theta0 0*theta0 1.05*theta0 0.95*theta0 ones(size(theta0,1),1) theta0_straight 1.05*theta0_straight 0.95*theta0_straight randn(size(theta0,1),10)];
    
    gamma=1e-6;
       
    user_input=user_pack(share,p,y,xi1,xi2,n1,n2,k1,k2,tau,gamma,p_grid_constraint,y_grid_constraint);
    
    theta=reg_demand_share_mean(user_input,x0_start_mat,set_constraint);
            
        %%%%%%%%%%%%%%%%%%
        % OUTPUT
        %%%%%%%%%%%%%%%%%%
    
end;

    %%%%%%%%%%%%%%%%%%%%%%%%%%
	% LINEAR QUANTILE REGRESSION
	%%%%%%%%%%%%%%%%%%%%%%%%%%

if config_id==5, 

        %%%%%%%%%%%%%%%%%%
        % LOAD IN
        %%%%%%%%%%%%%%%%%%

    S=config.S;
    share=config.share;
    tau=config.tau;
    theta0=NaN;
        
        %%%%%%%%%%%%%%%%%%
        % ESTIMATE
        %%%%%%%%%%%%%%%%%%
        
    [theta,~]=qreg_NAG(S,share,tau,theta0,1);
                   
end;


    %
